<?php


$params = require __DIR__ . '/params.php';
$initConfig = require __DIR__ . '/config.php';
$logConfig = require __DIR__.'/log.php';

$config = [
    'id' => 'basic-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'timeZone' => 'Asia/Shanghai',
    'controllerNamespace' => 'app\commands',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        /*'cache' => [
            'class' => 'yii\caching\FileCache',
        ],*/
        'log' => $logConfig,
        'db'=> $initConfig['db']['mysql'],

    ],
    'params' => $params,

    'controllerMap' => [
       /* 'fixture' => [ // Fixture generation command line.
            'class' => 'yii\faker\FixtureController',
        ],*/
        'serve'=>[
            'class'=>yii\console\controllers\ServeController::className(),
            'doroot'=>'@web'
        ],
        'swoole'=>[
            'class' => \Myswoole\Swoole\console\SwooleController::className(),
            'rootDir' => str_replace('config','',__DIR__), //yii2项目根路径
            'type'=> 'basic',
            'app' => '',//app目录地址
            'host' => '0.0.0.0',//监听地址
            'port' => $initConfig['swoole']['port'],//监听地址
            'swooleConfig'=>[
                'reactor_num' => $initConfig['swoole']['reactor_num'],
                'worker_num' => $initConfig['swoole']['worker_num'],
                'max_request'=> 150,//每个worker进程允许处理的最大任务数
                // //说明：设置该值后，每个worker进程在处理完max_request个请求后就会自动重启。设置该值的主要目的是为了防止worker进程处理大量请求后可能引起的内存溢出。
                'dispatch_mode'=>2,//指定数据包分发策略。
                //1 => 轮循模式，收到会轮循分配给每一个worker进程
                // 2 => 固定模式，根据连接的文件描述符分配worker。这样可以保证同一个连接发来的数据只会被同一个worker处理
                //3 => 抢占模式，主进程会根据Worker的忙闲状态选择投递，只会投递给处于闲置状态的Worker
                'max_conn'=>50000,//服务器允许维持的最大TCP连接数

                //'package_max_length' => 20 * 1024 * 1024, //请求包最大长度 设置为5M大小,在swoole v4.2.2有效  cli php.ini upload_max_filesize 设置为 5M
                'daemonize' => true,
                'log_file'=>__DIR__.'/../runtime/log/swoole.log',
                'log_level'=>0,
                'pid_file'=>__DIR__.'/../runtime/log/server.pid',
            ],
        ],

    ],

];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

return $config;
